package com.margo.project.curator.lock;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
import org.apache.curator.retry.ExponentialBackoffRetry;

public class MargoDistributedLock {
	public static void main(String[] args) {
		CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient("localhost:2181",
				new ExponentialBackoffRetry(1000, 3));
		curatorFramework.start();

		InterProcessMutex interProcessMutex=new InterProcessMutex(curatorFramework,"/reentrantlock");
		try {
			interProcessMutex.acquire();
			Thread.sleep(60000);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				interProcessMutex.release();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
